#!/usr/bin/env tsx

import { spawnSync } from 'node:child_process'
import process from 'node:process'

function run(cmd: string, args: string[]) {
  const r = spawnSync(cmd, args, { stdio: 'inherit', shell: process.platform === 'win32' })
  if (r.status !== 0) {
    process.exit(r.status ?? 1)
  }
}

console.log('🧩 Generating Prisma client...')
run('npx', ['prisma', 'generate'])

console.log('🗃️  Pushing Prisma schema to SQLite (db push)...')
run('npx', ['prisma', 'db', 'push', '--accept-data-loss'])

console.log('✅ Database schema is up-to-date.')
